package com.mm.cloud.sys.controller;


import com.mm.cloud.common.core.result.Result;
import com.mm.cloud.common.security.annotation.PreAuthorize;
import com.mm.cloud.sys.dto.form.DictTypeDTO;
import com.mm.cloud.sys.dto.query.QueryDictTypeDTO;
import com.mm.cloud.sys.service.IDictTypeService;
import com.mm.cloud.sys.vo.DictTypeVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 字典类型 前端控制器
 * </p>
 *
 * @author mr
 * @since 2022-11-12
 */
@Tag(name = "字典类型")
@RestController
@AllArgsConstructor
@RequestMapping("/sys/dictType")
public class DictTypeController {

    /**
     * 字典类型
     */
    private final IDictTypeService dictTypeService;

    @Operation(summary = "分页查询【mr】", description = "分页查询")
    @PostMapping("/getDicTypeList")
    @PreAuthorize(hasAuthorize = "ROLE_DICT_TYPE_LIST")
    public Result<List<DictTypeVO>> getDecTypeList(@RequestBody QueryDictTypeDTO dto) {
        return dictTypeService.getDecTypeList(dto);
    }

    @Operation(summary = "新增字典类型【mr】", description = "新增字典类型")
    @PostMapping("/saveDicType")
    @PreAuthorize(hasAuthorize = "ROLE_DICT_TYPE_ADD")
    public Result<String> saveDicType(@RequestBody DictTypeDTO dto) {
        return dictTypeService.saveDicType(dto);
    }

    @Operation(summary = "修改字典类型【mr】", description = "修改字典类型")
    @PostMapping("/updateDicType")
    @PreAuthorize(hasAuthorize = "ROLE_DICT_TYPE_EDIT")
    public Result<String> updateDicType(@RequestBody DictTypeDTO dto) {
        return dictTypeService.updateDicType(dto);
    }

    @Operation(summary = "删除字典类型【mr】", description = "删除字典类型")
    @PostMapping("/deleteDicType/{dictTypeId}")
    @PreAuthorize(hasAuthorize = "ROLE_DICT_TYPE_DELETE")
    public Result<String> deleteDicType(@PathVariable("dictTypeId") Long dictTypeId) {
        return dictTypeService.deleteDicType(dictTypeId);
    }

}

